package com.yc.ycpaimon.mapper

import com.yc.jetpacklib.mapper.IMapper
import com.yc.jetpacklib.utils.YcVersionUtil
import com.yc.ycpaimon.data.entity.VersionEntity
import com.yc.ycpaimon.data.json.VersionJson

/**
 * Creator: yc
 * Date: 2022/2/17 18:31
 * UseDes:
 */
class VersionMapper : IMapper<VersionJson, VersionEntity> {
    override fun map(input: VersionJson): VersionEntity {
        val versionNameNew = input.name ?: "0"
        return if (YcVersionUtil.versionName.compareTo(versionNameNew, true) < 0) {
            val apkInfo = input.assets!![0]
            val apkSize = (apkInfo.size ?: 0) / 1024.0 / 1024
            VersionEntity(true, apkInfo.browserDownloadUrl!!, String.format("本次更新大小：%.2f M", apkSize), input.body ?: "暂无更新内容", versionNameNew)
        } else {
            VersionEntity(false, null, null, null, null)
        }
    }
}